package com.shiro.shiroforadmin.pojo;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

public class Admin {

    public interface LoginGroup {}

    public interface UpdateUsernameGroup {}

    public interface UpdatePasswordGroup {}

    private static final long serialVersionUID = -7375937748809705055L;


    @NotNull(message = "ID不能为空", groups = {UpdateUsernameGroup.class,UpdatePasswordGroup.class})
    private Integer id;


    @NotBlank(message = "用户名不能为空", groups = {LoginGroup.class,UpdateUsernameGroup.class})
    private String username;


    @NotBlank(message = "密码不能为空", groups = {LoginGroup.class,UpdatePasswordGroup.class})
    private String password;


    private String token;


    private String salt;


    public Admin(Integer id, String username, String password, String token, String salt) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.token = token;
        this.salt = salt;
    }


    public Admin() {
        super();
    }


    public Integer getId() {
        return id;
    }


    public void setId(Integer id) {
        this.id = id;
    }


    public String getUsername() {
        return username;
    }


    public void setUsername(String username) {
        this.username = username;
    }


    public String getPassword() {
        return password;
    }


    public void setPassword(String password) {
        this.password = password;
    }


    public String getToken() {
        return token;
    }


    public void setToken(String token) {
        this.token = token;
    }


    public String getSalt() {
        return salt;
    }


    public void setSalt(String salt) {
        this.salt = salt;
    }


    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", username=").append(username);
        sb.append(", password=").append(password);
        sb.append(", token=").append(token);
        sb.append(", salt=").append(salt);
        sb.append("]");
        return sb.toString();
    }


    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Admin other = (Admin) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
                && (this.getUsername() == null ? other.getUsername() == null : this.getUsername().equals(other.getUsername()))
                && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
                && (this.getToken() == null ? other.getToken() == null : this.getToken().equals(other.getToken()))
                && (this.getSalt() == null ? other.getSalt() == null : this.getSalt().equals(other.getSalt()));
    }


    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getUsername() == null) ? 0 : getUsername().hashCode());
        result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
        result = prime * result + ((getToken() == null) ? 0 : getToken().hashCode());
        result = prime * result + ((getSalt() == null) ? 0 : getSalt().hashCode());
        return result;
    }
}